package com.runjian.rundo.iot.agent.iec104.enums;

import java.util.HashMap;
import java.util.Map;

import lombok.Getter;

/**
 * U帧控制域类型 _C:命令 _V:确认
 * 
 * @author CaoQingHua
 */
@Getter
public enum UFrameControlType {
    TESTFR_C((short)16, (short)32, Boolean.TRUE, "测试帧命令"), TESTFR_V((short)32, (short)0, Boolean.FALSE, "测试帧确认"),
    STOPDT_C((short)4, (short)8, Boolean.TRUE, "关闭数据传输"), STOPDT_V((short)8, (short)0, Boolean.FALSE, "关闭数据传输确认"),
    STARTDT_C((short)1, (short)2, Boolean.TRUE, "数据传输开始"), STARTDT_V((short)2, (short)0, Boolean.FALSE, "数据传输确认");

    short code;
    short downCode;
    boolean isDown;
    String name;

    UFrameControlType(short code, short downCode, boolean isDown, String name) {
        this.code = code;
        this.downCode = downCode;
        this.isDown = isDown;
        this.name = name;
    }

    private static final Map<Short, UFrameControlType> CODE_TO_ENUM_MAP = new HashMap<>();

    static {
        for (UFrameControlType type : values()) {
            CODE_TO_ENUM_MAP.put(type.code, type);
        }
    }

    public static UFrameControlType get(short code) {
        return CODE_TO_ENUM_MAP.get(code);
    }
}
